<template>
    <div class="trends">
        <div class="trends-top mb-20">
            <Breadcrumb router />
            <div class="row f f-ac">
                <div class="row-title">检索：</div>
                <div class="f-1">
                    <el-input v-model="queryForm.search" placeholder="输入关键词" size="small" clearable
                        style="width: 242px; margin-right: 44px" @change="search" />
                </div>
            </div>
            <!-- <div class="row f f-ac">
                <div class="row-title">日期范围：</div>
                <div>
                    <el-date-picker v-model="queryForm.startTime" type="date" placeholder="选择开始日期" style="width: 140px"
                        size="small" :picker-options="startPicker"  @change="handleStart" value-format="yyyy-MM-dd"/>
                    -
                    <el-date-picker v-model="queryForm.endTime" type="date" size="small" placeholder="选择结束日期"
                        style="width: 140px" :picker-options="endPicker" @change="handleEnd" value-format="yyyy-MM-dd"/>
                </div>
            </div> -->
        </div>
        <div class="trends-bottom">
            <div v-for="(i, k) in dataList" :key="k" class="trends-item f" :class="{ checked: i.hover }"
                @click="handleDetail(i)" @mouseover="i.hover = true" @mouseleave="i.hover = false">
                <img :src="baseUrl + i.image" />
                <div class="info">
                    <div class="f f-ac f-jb">
                        <div class="f-1">
                            <div class="item-title f f-ac f-js">
                                <div class="line-1">{{ i.title || "-" }}</div>
                            </div>
                            <div class="item-row line-2" v-html="i.msg" />
                            <div class="item-row">{{ i.createtime || "-" }}</div>
                        </div>
                        <div class="date f f-col f-ac f-jc">
                            <div>{{ splitData(i.createtime, "day") }}</div>
                            <div>{{ splitData(i.createtime, "month") }}</div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <Page-tool :size="queryForm.pageSize" :page="queryForm.currentPage" :total="total" @change-page="changePage" />
    </div>
</template>

<script>
    import {
        heritageList
    } from "@/utils/heritage/index.js";
    export default {
        data() {
            return {
                id: '',
                baseUrl: process.env.VUE_APP_BASE_API,
                queryForm: {
                    search: "", // 搜索关键词
                    startTime: "", // 开始时间
                    endTime: "", // 结束时间
                    pageSize: 12, // 条数
                    currentPage: 1, // 页数
                },
                total: 0, // 总数
                startPicker: {
                    // 开始时间限制
                    disabledDate: (time) => {
                        let endTime = this.queryForm.endTime;
                        if (endTime) return time.getTime() > new Date(endTime).getTime();
                    },
                },
                endPicker: {
                    // 结束时间限制
                    disabledDate: (time) => {
                        let startTime = this.queryForm.startTime;
                        if (startTime) return time.getTime() < new Date(startTime).getTime();
                    },
                },
                dataList: [],
            };
        },
        created() {

            this.id = this.$route.query.type
            this.getList();
        },
        methods: {
            search() {
                this.queryForm.currentPage = 1;
                this.getList();
            },
            handleStart(v) {
                this.queryForm.startTime = v
                this.queryForm.currentPage = 1;
                this.getList();
            },
            handleEnd(v) {
                this.queryForm.endTime = v
                this.queryForm.currentPage = 1;
                this.getList();
            },
            // 获取项目列表
            getList() {
                let that = this
                let data = {
                    heritage_category_id: that.id,
                    title: that.queryForm.search,
                    type: '',
                    page: that.queryForm.currentPage,
                    limit: 12,
                    recommend: ''
                }
                heritageList(data).then((response) => {
                    that.dataList = response.data.list
                        .map(item => {
                            return {
                                ...item,
                                hover: false
                            }
                        })

                    that.total = response.data.count
                });
            },
            // 查看详情
            handleDetail(v) {
                this.$router.push({
                    path: "/cultural/trendsDetails",
                    query: {
                        id: v.id,
                    },
                });
            },
            // 拆分日期
            splitData(date, unit) {
                if (unit == "day") {
                    return date.substr(8, 2);
                } else if (unit == "month") {
                    return date.substr(0, 7);
                } else {
                    return date || "-";
                }
            },
            // 切换页数
            changePage(page) {
                this.queryForm.currentPage = page;
                this.getList();
            },
        },
    };
</script>

<style lang="scss" scoped>
    .trends {
        width: 892px;
        min-height: 200px;
        margin: auto;

        .trends-top {
            width: 100%;
            border-radius: 8px;
            padding: 20px;
            box-sizing: border-box;
            background-color: #fff;
            box-shadow: 0px 0px 10px rgba(217, 217, 217, 0.3);

            .row {
                min-height: 36px;
                width: 100%;
                margin-top: 15px;

                &-title {
                    width: 90px;
                    color: #909090;
                    font-size: 14px;
                }

                .type-item {
                    display: inline-block;
                    min-width: 70px;
                    text-align: center;
                    height: 27px;
                    line-height: 27px;
                    color: #333;
                    background-color: #f4f4f4;
                    margin-right: 10px;
                    font-size: 12px;
                    border-radius: 3px;
                    padding: 0 10px;
                    box-sizing: border-box;

                    &:hover {
                        user-select: none;
                        cursor: pointer;
                    }
                }

                .checked {
                    color: #fff;
                    background-color: #193980;
                }
            }
        }

        .trends-bottom {
            width: 100%;

            .trends-item {
                margin-bottom: 30px;
                width: 100%;
                height: 160px;
                padding: 20px;
                box-sizing: border-box;
                border-radius: 10px;
                border: 1px solid transparent;
                box-shadow: 0 1px 10px 0 rgba(217, 217, 217, 0.3);
                transition: all 0.5s;

                img {
                    width: 203px;
                    height: 120px;
                    border-radius: 8px;
                    margin-right: 20px;
                }

                .info {
                    width: 627px;

                    .item-title {
                        max-width: 500px;
                        color: #000000;
                        font-size: 16px;

                        >div:first-child {
                            max-width: 484px;
                        }
                    }

                    .item-row {
                        color: #909090;
                        width: 484px;
                        font-size: 12px;
                        margin: 10px 0;
                    }
                }

                .date {
                    width: 121px;
                    height: 121px;
                    color: #466ec5;
                    font-weight: 600;
                    font-size: 16px;
                    border-radius: 10px;
                    transition: all 0.5s;
                    border: 1px solid #466ec5;

                    >div:first-child {
                        font-size: 25px;
                    }
                }
            }

            .checked {
                cursor: pointer;
                border: 1px solid rgba(70, 110, 197, 0.3);
                box-shadow: 0px 0px 20px rgba(70, 110, 197, 0.3);

                .date {
                    color: #fff;
                    border: 1px solid #fff;
                    background-color: #466ec5;
                }
            }
        }
    }
</style>